home *** CD-ROM | disk | FTP | other *** search
/ Stolen Data 2 / Stolen Data 2.adf / Source / ThreeD.s < prev   
Text File  |  1989-11-02  |  5KB  |  320 lines

  1.     Incdir    Df1:
  2.     Include Source/CustomRegisters
  3.     Section    ThreeD,Code_c
  4.  
  5. Ciaapra = $BFE001
  6. Openlibrary = -30-522    
  7. Disable        = -120
  8. Enable        = -126
  9. Startlist   = 38
  10. Execbase = 4
  11.  
  12.     Move.l    Execbase,a6
  13.     Jsr    Disable(a6)
  14.  
  15. ;-------- Switch Copper DMA ----------
  16.  
  17.     Move.l    #Clstart,Cop1lc
  18.     Clr    Copjmp1
  19.  
  20.     Move.w    #$8780,Dmacon
  21.     Move.w    #$0020,Dmacon
  22.     Lea    Spr0data,a0
  23.     Moveq    #7,d0
  24. Clop
  25.     Clr.l    (a0)
  26.     Addq.l    #8,a0
  27.     Dbf    d0,Clop
  28.  
  29. ;------ Wait for Vertical position 1 --------
  30.  
  31. Wait:    Move.l    $dff004,d2
  32.     And.l    #$0001ff00,d2    
  33.     Cmp.l    #$00000100,d2
  34.     Bne.s    Wait
  35.  
  36.     Addq    #2,Zrot
  37.     And    #$1fe,Zrot
  38.     Addq    #2,Yrot
  39.     And    #$1fe,Yrot
  40.     Subq    #2,Xrot
  41.     And    #$1fe,Xrot
  42.     Bsr    TD_rout
  43.  
  44.     Btst    #6,Ciaapra
  45.     Bne    Wait
  46.  
  47. ;------ Restore old Copper list -----------
  48.  
  49.     Move.l    Execbase,a6
  50.     Move.l    #Grname,a1
  51.     Clr.l    d0
  52.     Jsr    Openlibrary(a6)
  53.     Move.l    d0,a4
  54.     Move.l    Startlist(a4),Cop1lc
  55.     Clr.w    Copjmp1
  56.     Move.w    #$83E0,Dmacon
  57.     Jsr    Enable(a6)
  58.     Clr.l    d0
  59.     Rts
  60.  
  61. ;--------- 3D graphics ------------
  62. TD_rout
  63.     Move.l    Current(pc),d0
  64.     Move    d0,Screen+2
  65.     Swap    d0
  66.     Move    d0,Screen+6
  67.     Eor.l    #$3000,Current
  68.     Move.l    Current(pc),a0
  69.     Move.l    #$1f00000,Bltcon0
  70.     Move.l    a0,Bltdpth
  71.     Clr    Bltadat
  72.     Clr    Bltdmod
  73.     Move    #256*64+20,Bltsize
  74.  
  75.     Move    #No_points-1,d7
  76.     Lea    Points(pc),a4    
  77.     Lea    Sintable+$40(pc),a1
  78.     Lea    Rotated_coords(pc),a2
  79.     Lea    Perspective(pc),a3
  80. TD_loop
  81.     Move    (a4)+,d0
  82.     Move    d0,d2
  83.     Move    (a4)+,d1
  84.     Move    d1,d3
  85.  
  86.     Move    Zrot(pc),d6
  87.     Muls    $40(a1,d6),d0
  88.     Muls    -$40(a1,d6),d1
  89.     Sub.l    d1,d0
  90.     Lsl.l    d0
  91.     Swap    d0        ;d0 holds intermediate x coord
  92.     Muls    -$40(a1,d6),d2
  93.     Muls    $40(a1,d6),d3
  94.     Add.l    d3,d2
  95.     Lsl.l    d2
  96.     Swap    d2        ;d2 holds intermediate y coord
  97.     Move    d2,d4
  98.  
  99.     Move    (a4)+,d1    ;z coord
  100.     Move    d1,d3
  101.     Move    Xrot(pc),d6
  102.     Muls    $40(a1,d6),d2
  103.     Muls    -$40(a1,d6),d1
  104.     Sub.l    d1,d2
  105.     Lsl.l    d2
  106.     Swap    d2        ;d2 holds the final y coord
  107.  
  108.     Muls    $40(a1,d6),d3
  109.     Muls    -$40(a1,d6),d4
  110.     Add.l    d4,d3
  111.     Lsl.l    d3
  112.     Swap    d3        ;d3 holds intermediate z coord
  113.  
  114.     Move    d0,d1
  115.     Move    d3,d4
  116.     Move    Yrot(pc),d6
  117.     Muls    $40(a1,d6),d3
  118.     Muls    -$40(a1,d6),d0
  119.     Sub.l    d0,d3
  120.     Lsl.l    d3
  121.     Swap    d3        ;d3 holds the final z coord
  122.     Muls    -$40(a1,d6),d4
  123.     Muls    $40(a1,d6),d1
  124.     Add.l    d4,d1
  125.     Lsl.l    d1
  126.     Swap    d1        ;d1 holds the final x coord
  127.  
  128.     Add    #145,d3
  129.     And    #$fffe,d3
  130.     Move    (a3,d3),d5
  131.     Muls    d5,d1
  132.     Muls    d5,d2
  133.     Lsl.l    d1
  134.     Swap    d1
  135.     Add    #160,d1
  136.     Lsl.l    d2
  137.     Swap    d2
  138.     Add    #128,d2
  139.     
  140.     Move    d1,(a2)+
  141.     Move    d2,(a2)+
  142.     Dbf    d7,TD_loop
  143.  
  144.     Move    #No_connects-1,d7
  145.     Lea    $dff000,a5
  146.     Lea    Connect(pc),a3
  147.     Lea    Rotated_coords(pc),a4
  148.     Move.l    #40,a1
  149.     Move.l    #$ffff,a2
  150. B_wait2
  151.     Btst    #14,Dmaconr
  152.     Bne.s    B_wait2
  153.  
  154.     Move    #$ffff,Bltafwm
  155.     Move    a1,$60(a5)    ;Bltcmod
  156.     Move    a1,$66(a5)    ;Bltdmod
  157.     Move    a2,$72(a5)    ;Bltbdat
  158. Draw_loop
  159.     Move    (a3)+,d6
  160.     Move    (a4,d6),d0
  161.     Move    2(a4,d6),d1
  162.     Move    (a3)+,d6
  163.     Move    (a4,d6),d2
  164.     Move    2(a4,d6),d3
  165.     Cmp    d0,d2
  166.     Bne.s    Draw
  167.     Cmp    d1,d3
  168.     Beq.s    Nodraw    
  169. Draw
  170.     Bsr    Line
  171. Nodraw
  172.     Dbf    d7,Draw_loop
  173. Bwit
  174.     Btst    #14,Dmaconr
  175.     Bne.s    Bwit
  176.     Rts
  177.  
  178. ;----------- Line Draw ------------
  179. Line
  180.     Move    a1,d4
  181.     Mulu    d1,d4
  182.     Moveq    #-$10,d5
  183.     And    d0,d5
  184.     Lsr    #3,d5
  185.     Add    d5,d4
  186.     Add.l    a0,d4
  187.  
  188.     Clr.l    d5
  189.     Sub    d1,d3
  190.     Roxl.b    d5
  191.     Tst    d3
  192.     Bge.s    Y2gy1
  193.     Neg    d3
  194. Y2gy1
  195.     Sub    d0,d2
  196.     Roxl.b    d5
  197.     Tst    d2
  198.     Bge.s    X2gx1
  199.     Neg    d2
  200. X2gx1
  201.  
  202.     Move    d3,d1
  203.     Sub    d2,d1
  204.     Bge.s    Dygdx
  205.     Exg    d2,d3
  206. Dygdx
  207.     Roxl.b    d5
  208.     Move.b    Octant_table(pc,d5),d5
  209.     Add    d2,d2
  210. Wblit
  211.     Btst    #14,Dmaconr
  212.     Bne.s    Wblit
  213.  
  214.     Move    d2,$62(a5)    ;Bltbmod
  215.     Sub    d3,d2
  216.     Bge.s    Signn1
  217.     Or.b    #$40,d5
  218. Signn1
  219.     Move    d2,$52(a5)    ;Bltaptl
  220.     Sub    d3,d2
  221.     Move    d2,$64(a5)    ;Bltamod
  222.  
  223.     Move    #$8000,$74(a5)    ;Bltadat
  224.     And    #$000f,d0
  225.     Ror.w    #4,d0
  226.     Or    #$0bca,d0
  227.     Move    d0,$40(a5)    ;Bltcon0
  228.     Move    d5,$42(a5)    ;Bltcon1
  229.     Move.l    d4,$48(a5)    ;Bltcpth
  230.     Move.l    d4,$54(a5)    ;Bltdpth
  231.     Lsl    #6,d3
  232.     Addq    #2,d3
  233.     Move    d3,$58(a5)    ;Bltsize
  234.     Rts
  235.  
  236. ;---------- Constants -------------
  237.  
  238. Octant_table
  239.     Dc.b    1,17,9,21,5,25,13,29
  240.  
  241. Grname:    Dc.b    "graphics.library",0
  242.  
  243.     Even
  244.  
  245. ;----------- Variables ------------
  246.  
  247. Xrot    Dc.w    $100
  248. Yrot    Dc.w    0
  249. Zrot    Dc.w    0
  250. Current    Dc.l    $70000
  251.  
  252. ;---------- Copperlists -----------
  253. Clstart:
  254.     Wait    0,20
  255.     Mov    $1a81,Diwstrt
  256.     Mov    $39c1,Diwstop
  257.     Mov    $0038,Ddfstrt
  258.     Mov    $00d0,Diwstop
  259. Screen
  260.     Mov    0,Bpl1ptl
  261.     Mov    7,Bpl1pth
  262.     Mov    $1200,Bplcon0
  263.     Mov    0,Bpl1mod
  264.     Mov    0,Color00
  265.     Mov    $fff,Color01
  266.     Wait    224,255
  267.     Wait    $fe,$ff
  268.  
  269. ;--------- Binaries -------------
  270. No_points = 15
  271. No_connects = 19
  272.  
  273. Points
  274.     Dc.w    0,80,0
  275.     Dc.w    0,50,0
  276.     Dc.w    20,30,0
  277.     Dc.w    55,-5,0
  278.     Dc.w    45,-15,0
  279.     Dc.w    35,-15,0
  280.     Dc.w    25,-20,-15
  281.     Dc.w    -25,-20,-15
  282.     Dc.w    -35,-15,0
  283.     Dc.w    -45,-15,0
  284.     Dc.w    -55,-5,0
  285.     Dc.w    -20,30,0
  286.     Dc.w    27,-12,10
  287.     Dc.w    -27,-12,10
  288.     Dc.w    0,-30,-15
  289. Connect
  290.     Dc.w    0,4
  291.     Dc.w    4,8
  292.     Dc.w    8,12
  293.     Dc.w    12,16
  294.     Dc.w    16,20
  295.     Dc.w    20,24
  296.     Dc.w    24,28
  297.     Dc.w    28,32
  298.     Dc.w    32,36
  299.     Dc.w    36,40
  300.     Dc.w    40,44
  301.     Dc.w    44,4
  302.  
  303.     Dc.w    20,48
  304.     Dc.w    48,52
  305.     Dc.w    52,32
  306.  
  307.     Dc.w    48,4
  308.     Dc.w    52,4
  309.     Dc.w    24,4
  310.     Dc.w    28,4
  311.  
  312. Rotated_coords
  313.     Dcb.w    No_points*2,0
  314. Sintable
  315.     Incbin    Binary/Sin
  316.     Incbin    Binary/Sin
  317. Perspective
  318.     Incbin    Binary/Perspective
  319.  
  320.